Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add page translate function #1379

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

feat: add page translate function #1379

wants to merge 2 commits into from

Conversation

mo-bai
Copy link

@mo-bai mo-bai commented Jan 14, 2023

What?

I added one [translate] function to the PDFPage class . the method can translate annotations and content of the PDF's page . not only then content .

let source = await PDFDocument.load(readFile(path))
const pdfDoc = await PDFDocument.create()
let pages = await pdfDoc.copyPages(source, source.getPageIndices())
for (let page of pages) {
page.translate(50,50)
pdfDoc.addPage(page)
const pdfBytes = await pdfDoc.save()

Why?

In many pdf files, annotations and text content is followed together, the library currently only provides the translateContent method, if you use the method will cause misalignment of annotations and text . also , there are no methods in the library for moving annotations

How?

In my method, I first find all the annotations and then trnaslate the annotations by adding or subtracting numbers from the location information in the annotations

Testing?

I created a pdf file, marked the annotation on top of a word, and then use my method [ translate(20,20) ] , and then check if the annotation deviates from the word . Result: No offset . then repeat doing this test by using different annotation type

New Dependencies?

no

Screenshots

1673705834409
the yellow line is annotation
1673705895780

Suggested Reading?

Yes , but the url(https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf) is 404

Anything Else?

Checklist

  • I read CONTRIBUTING.md.
  • I read MAINTAINERSHIP.md#pull-requests.
  • I added/updated unit tests for my changes.
  • I added/updated integration tests for my changes.
  • I ran the integration tests.
  • I tested my changes in Node, Deno, and the browser.
  • I viewed documents produced with my changes in Adobe Acrobat, Foxit Reader, Firefox, and Chrome.
  • I added/updated doc comments for any new/modified public APIs.
  • My changes work for both new and existing PDF files.
  • I ran the linter on my changes.

@anodynos
Copy link

@mo-bai please check my comment here

Copy link

@Sharcoux Sharcoux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing:

  • tests
  • documentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants